<template>
  <div class="app-container">
    <div class="my-define-dialog-title">
      {{title}}
      <div class="my-define-dialog-title-btn">
        <el-button size="mini" type="primary" @click.native="submitForm">提 交</el-button>
        <el-button size="mini" @click.native="cancel(false)">取 消</el-button>
      </div>
    </div>
    <el-scrollbar :style="customeStyle">
      <el-form ref="myForm" :model="form" :label-width="labelForm.labelWidth" :label-position="labelForm.labelPosition">
        <el-row>
          <el-col :span="24">
            <el-form-item label="租户名称" :prop="'TenantName'" :rules="{
                  required: true, message: '请输入租户名称', trigger: 'change'}">
              <el-input v-model="form.TenantName" placeholder="请输入" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-scrollbar>
  </div>
</template>

<script>
  import {
    getTenant,
    saveTenant
  } from '@/api/users/tenants'
  import defaultSettings from '@/settings'
  export default {
    name: 'tenant-edit',
    props: {
      Id: {
        type: Number,
        default: 0
      },
      title: {
        type: String,
        default: ''
      }
    },
    data() {
      return {
        customeStyle: {
          height: (window.innerHeight - 180) + 'px'
        },
        labelForm: defaultSettings.labelForm,
        form: {
          Id: 0
        }
      }
    },
    created() {
      this.getData()
    },
    methods: {
      /** 查询列表 */
      getData() {
        getTenant(this.Id).then(res => {
          if (res.status) {
            this.form = res.outputData.model;
          }
        })
      },
      submitForm() {
        var that = this;
        this.$refs['myForm'].validate(valid => {
          if (valid) {
            saveTenant(this.form).then(res => {
              if (res.status) {
                this.$message({
                  message: this.form.Id > 0 ? '修改成功' : '新增成功',
                  type: 'success'
                })
                this.cancel(true);
              }
            })
          }
        })
      },
      cancel(reload) {
        this.$$parent(this, "doCloseDetail", reload)
      }
    }
  }
</script>
